f = [0] * (10**3 + 10)
f[1] = 1
f[2] = 2

for i in range(3, 10**3 + 10):
    f[i] = (2 * f[i - 1] + 3 * f[i - 2] + i) % (1e9 + 7)

while 1:
    n = int(input())
    if n == 0:
        break
    else:
        print(int(f[n]))